<template>
  <div id="purchase-order">
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane
        :label="item"
        :name="item"
        v-for="item in nameList"
        :key="item"
      >
      <!-- 动态组件 -->
      <!-- 给要显示的table起名字,通过$refs获取 -->
        <orderTable ref="msg"></orderTable>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>
<script>
import orderTable from "./orderTable";
export default {
  data() {
    return {
      activeName: "所有订单",
      nameList: [
        "所有订单",
        "待支付",
        "待派单",
        "待接单",
        "待服务",  
        "待确认",
        "已完成",
      ],
    };
  },
  methods: {
    handleClick(tab, event) {
      //获取当前的选项卡,发送它的名字作为请求参数
      // tab.index为当前点击的选项卡
      this.$refs.msg[tab.index].sendItem(this.activeName);
    },
  },
  components: {
    orderTable,
  },
  //挂载阶段发送所有订单请求
  mounted() {
    this.$refs.msg[0].sendItem(this.activeName);
  },
};
</script>

<style lang="scss" scoped>
#purchase-order {
  padding: 20px;
}
</style>
